package com.zrar.ak.gkpt.controller.record;


import com.zrar.ak.gkpt.model.vo.UserVO;
import com.zrar.ak.gkpt.service.record.IBusinessBidPurchaseService;
import com.zrar.ak.gkpt.service.user.IUserService;

import com.zrar.ak.gkpt.util.FormDataParameter;
import com.zrar.ak.gkpt.util.JsonPageResult;
import com.zrar.ak.gkpt.util.JsonResult;
import io.swagger.annotations.Api;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


/**
 * @ClassName: BusinessBidPurchaseController
 * @Description 招标采购Controller层
 * @Author HuangKeXin
 * @Time 2020/04/4
 */
@RestController
@RequestMapping("/businessbid")
@Api(tags = "招标采购相关接口")
public class BusinessBidPurchaseController {
    @Autowired
    private IBusinessBidPurchaseService businessBidPurchaseService;
    @Autowired
    private IUserService userService;

    @RequestMapping(value = "bidBasicInfoSave", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "招标信息保存", httpMethod = "POST", notes = "招标信息保存")
    public JsonResult businessBidSave(HttpServletRequest request,
                                      @ApiParam(name = "formDataParameter", value = "招标信息保存数据参数") @RequestBody FormDataParameter formDataParameter) {
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVO = userService.getUserInformation(request);
        jsonResult = businessBidPurchaseService.businessBidSave(jsonResult, formDataJson, userVO);
        return jsonResult;
    }

    @RequestMapping(value = "bidBasicInfoUpdate", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "招标信息修改", httpMethod = "POST", notes = "招标信息修改")
    public JsonResult businessBidUpdate(HttpServletRequest request,
                                        @ApiParam(name = "formDataParameter", value = "招标信息修改数据参数") @RequestBody FormDataParameter formDataParameter) {
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVO = userService.getUserInformation(request);
        jsonResult = businessBidPurchaseService.businessBidUpdate(jsonResult, formDataJson, userVO);
        return jsonResult;
    }
//
//    @RequestMapping(value = "purchaseInfoSave", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
//    @ApiOperation(value = "采购信息保存", httpMethod = "POST", notes = "采购信息保存")
//    public JsonResult businessPurchaseSave(HttpServletRequest request,
//                                           @ApiParam(name = "formDataParameter", value = "采购信息保存数据参数") @RequestBody FormDataParameter formDataParameter) {
//        JsonResult jsonResult = new JsonResult();
//        String formDataJson = formDataParameter.getFormDataJson();
//        UserVO userVO = userService.getUserInformation(request);
//        jsonResult = businessBidPurchaseService.businessPurchaseSave(jsonResult, formDataJson, userVO);
//        return jsonResult;
//    }
//
//    @RequestMapping(value = "purchaseInfoUpdate", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
//    @ApiOperation(value = "采购信息修改", httpMethod = "POST", notes = "采购信息修改")
//    public JsonResult businessPurchaseUpdate(HttpServletRequest request,
//                                             @ApiParam(name = "formDataParameter", value = "采购信息修改数据参数") @RequestBody FormDataParameter formDataParameter) {
//        JsonResult jsonResult = new JsonResult();
//        String formDataJson = formDataParameter.getFormDataJson();
//        UserVO userVO = userService.getUserInformation(request);
//        jsonResult = businessBidPurchaseService.businessPurchaseUpdate(jsonResult, formDataJson, userVO);
//        return jsonResult;
//    }

    @RequestMapping(value = "bidInfoGet", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "根据建设单位编码获取招标信息", httpMethod = "GET", notes = "根据建设单位编码获取招标信息")
    public JsonResult businessBidInfoGetByUnitId(HttpServletRequest request,
                                                 @ApiParam(name = "unitId", value = "建设单位编码") @RequestParam String unitId) {
        JsonResult jsonResult = new JsonResult();
        jsonResult = businessBidPurchaseService.businessBidInfoGetByUnitId(jsonResult, unitId);
        return jsonResult;
    }

    @RequestMapping(value = "deleteBid", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "根据建设单位编码将对应的招标信息置为无效", httpMethod = "GET", notes = "根据建设单位编码将对应的招标信息置为无效")
    public JsonResult deleteBusinessBidInfoByUnitId(HttpServletRequest request,
                                                           @ApiParam(name = "unitId", value = "建设单位编码") @RequestParam String unitId,
                                                           @ApiParam(name = "bidType", value = "招标处理类型(1:招标基本信息和采购信息执行删除操作 2:采购信息执行删除操作)") @RequestParam(value = "bidType", required = false, defaultValue = "1") String bidType) {
        JsonResult jsonResult = new JsonResult();
        jsonResult = businessBidPurchaseService.deleteBusinessBidInfoByUnitId(jsonResult, unitId, bidType);
        return jsonResult;
    }

    @RequestMapping(value = "getBidPurchaseInfoList", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "获取招标信息列表-分页查询和条件查询", httpMethod = "GET", notes = "获取招标信息列表-分页查询和条件查询")
    public JsonPageResult getBusinessBidInfoList(HttpServletRequest request,
                                                 @ApiParam(name = "currentPage", value = "当前页") @RequestParam int currentPage,
                                                 @ApiParam(name = "pageSize", value = "每页条数限制") @RequestParam int pageSize,
                                                 @ApiParam(name = "projectName", value = "项目名称(模糊查询)") @RequestParam(value = "projectName", required = false) String projectName,
                                                 @ApiParam(name = "bidWay", value = "招标方式(模糊查询)") @RequestParam(value = "bidWay", required = false) String bidWay) {
        JsonPageResult jsonResult = new JsonPageResult();
        jsonResult = businessBidPurchaseService.getBusinessBidInfoList(jsonResult, currentPage, pageSize, projectName,bidWay);
        return jsonResult;
    }















    @RequestMapping(value = "SavePurchase", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "保存采购详细信息", httpMethod = "POST", notes = "保存采购详细信息")
    public JsonResult schemeInfoSave(HttpServletRequest request,
                                     @ApiParam(name = "formDataParameter", value = "采购信息数据参数") @RequestBody FormDataParameter formDataParameter) {
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVO = userService.getUserInformation(request);
        jsonResult = businessBidPurchaseService.purchaseInfoSave(jsonResult, formDataJson, userVO);
        return jsonResult;
    }

    @RequestMapping(value = "deletePurchase", method = RequestMethod.DELETE, produces = {"application/json;charset=utf-8"})
    @ApiOperation(value = "删除采购信息", httpMethod = "DELETE", notes = "删除采购信息")
    public JsonResult schemeInfoDeleteById(HttpServletRequest request,
                                           @ApiParam(name = "basicsId", value = "基础信息表主键") @RequestParam(value ="basicsId") String basicsId) {
        JsonResult jsonResult = new JsonResult();
        jsonResult = businessBidPurchaseService.deletePurchaseByBasicsId(jsonResult,basicsId);
        return jsonResult;
    }

    @RequestMapping(value = "queryPurchase", method = RequestMethod.GET, produces = {"application/json;charset=utf-8"})
    @ApiOperation(value = "查看采购信息", httpMethod = "GET", notes = "查看采购信息")
    public JsonResult schemeInfoGetById(@ApiParam(name = "id", value = "主键id") @RequestParam(value ="id") String id) {
        JsonResult jsonResult = new JsonResult();
        jsonResult = businessBidPurchaseService.queryPurchaseByUnitId(jsonResult,id);
        return jsonResult;
    }

    @RequestMapping(value = "updatePurchase", method = RequestMethod.PUT, produces = {"application/json;charset=utf-8"})
    @ApiOperation(value = "更新采购信息", httpMethod = "PUT", notes = "更新采购信息")
    public JsonResult schemeInfoUpdate(HttpServletRequest request, @ApiParam(name = "formDataParameter", value = "更新采购信息参数") @RequestBody FormDataParameter formDataParameter) {
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVO = userService.getUserInformation(request);
        jsonResult = businessBidPurchaseService.purchaseInfoUpdate(jsonResult, formDataJson, userVO);
        return jsonResult;
    }





}
